import os

from auto_frame.base import Base
from selenium.webdriver.remote.webdriver import WebDriver
from page.add_member_page import AddMemberPage
from page.contact_page import ContactPage
from page.import_contact_page import ImportContactPage

#微信主页面
class IndexPage(Base):
    url = 'https://work.weixin.qq.com/wework_admin/loginpage_wx?from=myhome'

    #初始化driver
    def __init__(self,driver:WebDriver):
       super(IndexPage,self).__init__(driver)
       cur_path = os.path.abspath(os.path.dirname(__file__))  # 获取当前文件目录
       root_path = os.path.dirname(cur_path)
       self.step_path = f'{root_path}/steps/index_page.yaml'
       self.cookies_path = f'{root_path}/bo/cookies.yaml'

       driver.get(self.url)
       self.set_cookies(driver, self.cookies_path, "cookies")
       driver.get(self.url)

    #跳转到通讯录页面
    def goto_contact_page(self):
        self.steps(self.step_path,"goto_contact_page")
        return ContactPage(self.driver)

    #跳转添加成员页面
    def goto_add_member_page(self):
        self.steps(self.step_path, "goto_add_memnber_page")
        return AddMemberPage(self.driver)

    #跳转到导入通讯录页面
    def goto_import_contact_page(self):
        self.steps(self.step_path, "goto_import_contact_page")
        return ImportContactPage(self.driver)